/**
 * File Created at 2016年5月4日
 * Copyright 2016 汉威.智慧环保事业部 Limited.
 * All rights reserved.
 */
package com.sc.datacollect.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * 认证配置
 * @author duqunxing
 *
 */
public class ClientConfig {
	private static Logger log = LoggerFactory.getLogger(ClientConfig.class);

	private static Properties properties = new Properties();

	private ClientConfig(){}
	
	private static ClientConfig clientConfig;
	
	/**
	 * 获取认证实例
	 * @return
	 */
	public static ClientConfig getInstance(){
		if(null == clientConfig){
			clientConfig = new ClientConfig();
			initConfig();
		}
		return clientConfig;

	}
	/**
	 * 初始化认证信息
	 */
	private static void initConfig(){
		initCustom();
	}
	
	private static void initCustom(){
		String customSrc = Common.dir + "client.properties";
		InputStream is = null;
		try {
			is = new FileInputStream(customSrc);
			if(is != null){
				properties.load(is);
				log.debug("加载自定义配置文件");
			}
		} catch (IOException e) {
			log.error("加载自定义配置文件错误",e);
		}finally {
			if(is != null){
				try {
					is.close();
				} catch (IOException e) {
					log.error("自定义配置文件流关闭错误",e);
				}
			}
		}
	}
	
	/**
	 * 获取uri
	 * @return
     */
	public String getUri(String key){
		return properties.getProperty(key);
	}

	/**
	 * 获取schema
	 * @return
     */
	public String  getSchema(){
		return properties.getProperty("schema");
	}

	/**
	 * 获取host
	 * @return
     */
	public  String getHost(){
		return properties.getProperty("host");
	}
	/**
	 * 获取port
	 * @return
     */
	public  String getPort(){
		return properties.getProperty("port");
	}
}
